<?php

//use Test;

class TestController extends \Phalcon\Mvc\Controller
{

    public function indexAction() {
        echo 'this is index.';
    }
    
    public function queryAction() {
	$res = User::find();

//var_dump($res);

        echo 'データ：'. count($res) . '件';
        foreach($res as $doc) {
            echo '<pre>';
            //print_r($doc);
	     print_r(get_object_vars($doc));
            echo '</pre>';
        }

    }

    public function insertAction() {
 
       $user = new User();
       $user->login = 'suzuki';
	$user->password = 'suzuki';
	$user->email = 'suzuki@example.com';
	$user->hobby = array('サッカー', 'ゲーム');

	if ($user->save() == false) {
	    echo "Umh, We can't store user right now: \n";
	    foreach ($user->getMessages() as $message) {
		echo $message, "\n";
	    }
	} else {
	    echo "Great, a new user was saved successfully!";
	}

       $user = new User();
       $user->login = 'sato';
	$user->password = 'sato';
	$user->email = 'sato@example.com';
	$user->hobby = array('ゲーム', '旅行');

	if ($user->save() == false) {
	    echo "Umh, We can't store user right now: \n";
	    foreach ($user->getMessages() as $message) {
		echo $message, "\n";
	    }
	} else {
	    echo "Great, a new user was saved successfully!";
	}


   }
}         


